package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.vo.PasswordDTO;
import com.miku.blog.service.UserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-05-26 0:21
 */
@Api(tags = "后台管理系统[用户]")
@RequestMapping("/admin")
@RestController
public class UserAuthController {

    @Autowired
    private UserAuthService userAuthService;

    @SystemLog(notes = "获取用户列表{后台管理系统}")
    @ApiOperation(value = "获取用户列表接口")
    @GetMapping("/users")
    public ResponseResult getUserList(@RequestParam("current")Integer current,
                                      @RequestParam("size")Integer size,
                                      @RequestParam(value = "loginType",required = false) Integer loginType,
                                      @RequestParam(value = "keywords",required = false)String keywords)
    {
        return userAuthService.getUserList(current,size,loginType,keywords);
    }

    @SystemLog(notes = "修改密码{后台管理系统}")
    @ApiOperation(value = "修改密码接口")
    @PutMapping("/users/password")
    public ResponseResult updatePassword(@RequestBody PasswordDTO passwordDTO){
        return userAuthService.updatePassword(passwordDTO);
    }

    @SystemLog(notes = "禁用/启用用户{后台管理系统}")
    @ApiOperation(value = "禁用/启用用户接口")
    @PutMapping("/users/disable/{userId}")
    public ResponseResult disable(@PathVariable("userId") Integer userId,
                                  @RequestParam("isDisable")Integer isDisable)
    {
        return userAuthService.disableByUserId(userId,isDisable);
    }

    @SystemLog(notes = "获取在线用户列表{后台管理系统}")
    @ApiOperation(value = "获取在线用户列表接口")
    @GetMapping("/users/online")
    public ResponseResult getOnlineUser(@RequestParam("current")Integer current,
                                        @RequestParam("size")Integer size,
                                        @RequestParam(value = "keywords",required = false)String keywords)
    {
        return userAuthService.getOnlineUser(current,size,keywords);
    }

    @SystemLog(notes = "强制下线用户{后台管理系统}")
    @ApiOperation(value = "强制下线用户接口")
    @DeleteMapping("/users/online")
    public ResponseResult offLineUser(@RequestBody Integer[] userIdList){
        return userAuthService.offLineUser(userIdList);
    }

}
